[LegacyColorValue = true]; 

{ TSM Divergence Index
  Copyright 2011 P J Kaufman. All rights reserved. }

{ period = length of calculaton
  crossoption =0 using trendline, =1 use price crossing trendline
}
  input: longperiod(40), shortperiod(10), factor(1.0);
  vars:	MAlong(0), MAshort(0), diff(0), DI(0), band(0);

	MAlong = average(close,longperiod);
	MAshort = average(close,shortperiod);
	diff = Close - close[1];
	DI = (MAshort - MAlong)/power(stddev(diff,longperiod),2);
	band = stddev(DI,longperiod);
	
	plot1(DI,"DI");
	plot2(band*factor,"UB");
	plot3(-band*factor,"LB");
	
			

